"""Defines a skype kernal.

Copyright Ian Blumel, 2009.
All Rights Reserved.
"""

import Skype4Py
from libskysh.kernal import kernal_t

class skype_kernal_t(kernal_t):
    def __init__(self, *args):
        kernal_t.__init__(self, *args)
        self.skype_api = Skype4Py.Skype()
        self.skype_api.OnMessageStatus = self._on_msg_stat
        
    def start(self):
        self.skype_api.Attach()

    def stop(self):
        pass

    def write(self, msg):
        self.msg.Chat.SendMessage(msg)

    def write_err(self, msg):
        # TODO write an actual error style, can we change the color
        # to red?
        self.msg.Chat.SendMessage(msg)

    def error(self, msg):
        self.msg.Chat.SendMessage(msg)

    def replace_all(self, msg):
        self.msg.Body = msg        

    def _on_msg_stat(self, msg, stat):
        if stat == "SENT":
            self.msg = msg 
            self.send(msg.Body)
